package com.loongtech.bi.action.player;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.loongtech.bi.action.BaseBiSearchAction;
import com.loongtech.bi.manager.player.ActivePlayerManager;
import com.loongtech.bi.manager.player.ActivePlayerManager.ActiveChannelData;
import com.loongtech.bi.manager.player.ActivePlayerManager.ActivePlatFormData;
import com.loongtech.bi.manager.player.ActivePlayerManager.ActiveServerData;
import com.loongtech.bi.manager.player.ActivePlayerManager.ActiveTendData;
import com.loongtech.bi.manager.system.SysLogManager;
import com.loongtech.bi.support.Session;
import com.loongtech.bi.support.chart.ChartTool;
import com.loongtech.bi.support.chart.ChartType;
import com.loongtech.bi.support.chart.ChartUIData;

/**
 * 玩家分析-活跃分析Action
 * @author Marin
 * @date 2015年09月17日
 */
@Controller
@Scope("view")
public class ActivePlayerAction extends BaseBiSearchAction {
	private static final long serialVersionUID = 1L;
	private List<ActiveTendData> dataList1;  // 前端要显示的数据1
	private ChartUIData chartData1;  // 前端要显示的柱状图1数据
	//平台对比
	private List<ActivePlatFormData> dataList2;
	private ChartUIData chartData2;
	//渠道对比
	private List<ActiveChannelData> dataList3;
	private ChartUIData chartData3;
	//区服对比
	private List<ActiveServerData> dataList4;
	private ChartUIData chartData4;
	@Autowired
	private ActivePlayerManager activePlayerManager;
	
	@Autowired
	private SysLogManager sysLogManager;
	@Autowired
	private Session session;
	
	@PostConstruct
	public void init() {
		search();
	}

	public void search() {
		sysLogManager.addLog(session.getUserName(), "查询玩家分析-活跃分析");
		
		chartData1 = null;
		chartData2 = null;
		chartData3 = null;
		chartData4 = null;
		dataList1 = activePlayerManager.getActiveTendData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
		
		if (dataList1 != null && dataList1.size() > 0) {
			chartData1 = new ChartUIData();
			chartData1.setJsonType(ChartType.SPLINE.type);
			chartData1.setJsonStr(new ChartTool(dataList1, ActiveTendData.class, "").loadData(chartData1.getJsonType()));
			//下拉框
			chartData1.setAllItmes(ChartTool.getAllItems(ActiveTendData.class));
		}
		
		//平台对比
		dataList2 = activePlayerManager.getActivePlatFormData(dateStart, dateEnd);
		if (dataList2 != null && dataList2.size() > 0) {
			chartData2 = new ChartUIData();
			chartData2.setJsonType(ChartType.SPLINE.type);
			chartData2.setJsonStr(new ChartTool(dataList2, ActivePlatFormData.class, "").loadData(chartData2.getJsonType()));
			chartData2.setAllItmes(ChartTool.getAllItems(ActivePlatFormData.class));
		}
		
		//渠道对比
		dataList3 = activePlayerManager.getActiveChannelData(dateStart, dateEnd);
		if (dataList3 != null && dataList3.size() > 0) {
			chartData3 = new ChartUIData();
			chartData3.setJsonType(ChartType.SPLINE.type);
			chartData3.setJsonStr(new ChartTool(dataList3, ActiveChannelData.class, "").loadData(chartData3.getJsonType()));
			chartData3.setAllItmes(ChartTool.getAllItems(ActiveChannelData.class));
		}
		
		//区服对比
		dataList4 = activePlayerManager.getActiveServerData(dateStart, dateEnd);
		if (dataList4 != null && dataList4.size() > 0) {
			chartData4 = new ChartUIData();
			chartData4.setJsonType(ChartType.SPLINE.type);
			chartData4.setJsonStr(new ChartTool(dataList4, ActiveServerData.class, "").loadData(chartData4.getJsonType()));
			chartData4.setAllItmes(ChartTool.getAllItems(ActiveServerData.class));
		}
	}
	
	//趋势图表的选择
	public void activeTendSelect() throws Exception {
		chartData1.setJsonStr(new ChartTool(dataList1, ActiveTendData.class, chartData1.getSelectItem()).loadData(chartData1.getJsonType()));
	}
	
	//平台的选择
	public void activePlatFormDataSelect() throws Exception {
		chartData2.setJsonStr(new ChartTool(dataList2, ActivePlatFormData.class, chartData2.getSelectItem()).loadData(chartData2.getJsonType()));
	}
	
	//渠道的选择
	public void activeChannelDataSelect() throws Exception {
		chartData3.setJsonStr(new ChartTool(dataList3, ActiveChannelData.class, chartData3.getSelectItem()).loadData(chartData3.getJsonType()));
	}
	
	//区服的选择
	public void activeServerDataSelect() throws Exception {
		chartData4.setJsonStr(new ChartTool(dataList4, ActiveServerData.class, chartData4.getSelectItem()).loadData(chartData4.getJsonType()));
	}
		
	@Override
	protected String csvContent() {
		return "活跃分析";
	}

	@Override
    protected String csvFileName() {
	    return "活跃分析";
    }

	public List<ActiveTendData> getDataList1() {
		return dataList1;
	}

	public void setDataList1(List<ActiveTendData> dataList1) {
		this.dataList1 = dataList1;
	}

	public ChartUIData getChartData1() {
		return chartData1;
	}

	public void setChartData1(ChartUIData chartData1) {
		this.chartData1 = chartData1;
	}

	public List<ActivePlatFormData> getDataList2() {
		return dataList2;
	}

	public void setDataList2(List<ActivePlatFormData> dataList2) {
		this.dataList2 = dataList2;
	}

	public ChartUIData getChartData2() {
		return chartData2;
	}

	public void setChartData2(ChartUIData chartData2) {
		this.chartData2 = chartData2;
	}

	public List<ActiveChannelData> getDataList3() {
		return dataList3;
	}

	public void setDataList3(List<ActiveChannelData> dataList3) {
		this.dataList3 = dataList3;
	}

	public ChartUIData getChartData3() {
		return chartData3;
	}

	public void setChartData3(ChartUIData chartData3) {
		this.chartData3 = chartData3;
	}

	public List<ActiveServerData> getDataList4() {
		return dataList4;
	}

	public void setDataList4(List<ActiveServerData> dataList4) {
		this.dataList4 = dataList4;
	}

	public ChartUIData getChartData4() {
		return chartData4;
	}

	public void setChartData4(ChartUIData chartData4) {
		this.chartData4 = chartData4;
	}
}
